package com.example.guestbook.service;

import java.util.List;

import com.example.guestbook.po.Greeting;
import com.example.guestbook.repository.GuestBookRepository;
import com.gaeig.base.Transactional;
import com.google.inject.Inject;

public class GuestBookServiceImpl implements GuestBookService {
  @Inject
  private GuestBookRepository repository;

  public GuestBookRepository getRepository() {
    return repository;
  }

  public void setRepository(GuestBookRepository repository) {
    this.repository = repository;
  }

  public List<Greeting> getAllGreetings() {
    return repository.getAllGreetings();
  }

  @Transactional
  public void saveGreeting(Greeting greeting) {
    repository.saveGreeting(greeting);
  }

  @Transactional
  public void deleteGreeting(Greeting greeting) {
    repository.deleteGreeting(greeting);
  }

  @Transactional
  public void testTransaction(Greeting greeting) {
    saveGreeting(greeting);
    throw new RuntimeException("break transaction!");
  }
}
